<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新美DSP系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--框架核心CSS库-->
    <link rel="stylesheet" href="__BACKEND_STATIC__/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="__BACKEND_STATIC__/css/font-awesome.min.css">
    <link rel="stylesheet" href="__BACKEND_STATIC__/css/global.css">
    <block name="style"></block>

</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>请选择物料</legend>
</fieldset>

<div class="layui-form">
    <table class="layui-table list-content-table" lay-skin="nob">
        <colgroup>
            <col width="50">
            <col width="100">
            <col width="200">
            <col width="200">
            <col width="200">
        </colgroup>

        <thead class="list-table-head">
            <tr>
                <th class="ui-table-hcell">
                    <div class="ui-table-hcell-text">
                        <input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" />
                    </div>
                </th>
                <th class="ui-table-hcell"><div class="ui-table-hcell-text">ID</div></th>
                <th class="ui-table-hcell"><div class="ui-table-hcell-text">物料名称</div></th>
                <th class="ui-table-hcell"><div class="ui-table-hcell-text">物料预览</div></th>
                <th class="ui-table-hcell"><div class="ui-table-hcell-text">物料尺寸</div></th>
            </tr>

        </thead>

        <tbody class="list-table-body">

            <foreach name="ad_lists" item="ad_data">
                <tr data-id="{$ad_data.id}" data-name="{$ad_data.ad_name}" data-img="//res.dbccv.com{$ad_data.image_url}" data-size="{$ad_data.ad_width}*{$ad_data.ad_height}">

                    <td class='ui-table-cell'>
                        <div class='ui-table-cell-text'><input type="checkbox" name="" lay-skin="primary" data-id="{$ad_data.id}" /></div>
                    </td>

                    <td class='ui-table-cell'>
                        <div class='ui-table-cell-text'>{$ad_data.id}</div>
                    </td>

                    <td class='ui-table-cell'>
                        <div class='ui-table-cell-text'>{$ad_data.ad_name}</div>
                    </td>

                    <td class='ui-table-cell'>
                        <div class='ui-table-cell-text'><img width="180" height="120px" src="//res.dbccv.com/{$ad_data.image_url}" /></div>
                    </td>

                    <td class='ui-table-cell'><div class='ui-table-cell-text'>{$ad_data.ad_width}*{$ad_data.ad_height}</div></td>

                </tr>
            </foreach>

        </tbody>
    </table>
    {$page}
</div>

<div class="layui-form-item">
    <div class="layui-input-block">

        <button id="transmit" class="layui-btn" lay-submit="" lay-filter="sub">　　保存　　</button>
        <button class="layui-btn layui-btn-primary close-btn" id="closeIframe">取消</button>
    </div>
</div>

<block name="script">
    <!--框架核心JS库-->
    <script src="__BACKEND_STATIC__/plugins/layui/layui.js"></script>
    <script src="__BACKEND_STATIC__/js/jquery.pjax.min.js"></script>
    <script src="__BACKEND_STATIC__/js/underscore-min.js"></script>
    <script src="__BACKEND_STATIC__/js/global.js"></script>
    <script src="__BACKEND_STATIC__/js/jquery/2.0.1/jquery.min.js"></script>
</block>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('form', function(){
        var $ = layui.jquery, form = layui.form();

        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });


    });
</script>

<script>

    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

    //给父页面传值
    $('#transmit').on('click', function(){
        var arr = [];
        var child = $('table').find('tbody input[type="checkbox"]');
        child.each(function(index, item){
            var parentDom = $(item).parents('tr');

            if( parentDom.find(".layui-form-checked").length == 1 ) {
                var param = {};
                param['id'] = parentDom.attr('data-id');
                param['name'] = parentDom.attr('data-name');
                param['img'] = parentDom.attr('data-img');
                param['size'] = parentDom.attr('data-size');
                arr.push(param);
            }
        });
        window.parent.parentFunction(arr);
        parent.layer.close(index);
    });

    //关闭iframe
    $('#closeIframe').click(function(){
        parent.layer.close(index);
    });

</script>

</body>
</html>